home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb13.arc
/
PASUTI.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-05-26
|
7KB
|
245 lines
(*************************************************************************)
(* A set of utilities for TURBO-Pascal on the IBM-PC and compatibles *)
(* for file-appending, checking Key-Locks and display-type. *)
(* Included ist wait_for_any_key, a procedure which responds to ANY key. *)
(* Uploaded by RMI Nachrichtentechnik GmbH, Aachen, West Germany *)
(* Author W. Siebeck, CIS 72446,415 *)
(*************************************************************************)
Type
line = string[255];
byte_type = file of byte;
const
eof_mark : byte = $1A;
Offset : integer = 3680;
(* Offset is needed in the lock_status procedure. It should be set to *)
(* 3680 to get the lock-display in line 25 of the screen *)
var
ScreenBase : integer;
demochar : char;
Procedure DetermineDisplay;
{ Set ScreenBase to $B000 or $B800, depending on which display is in use. }
{ This Version adapted from the IBM-BASIC-Manual }
Var
T: Byte;
Begin
t := (mem[0000:$0410] and $0030);
if (t=$0030) then ScreenBase := $B000
else ScreenBase := $B800
End;
(* Equivalent for the BASIC LEFT$(A$,M) *)
(* Returns the left i1 characters of st1 *)
function leftstr (st1: line; i1: byte): line;
var
tempst : line;
n : byte;
begin
tempst := '';
n:=length (st1);
if (n > i1) then tempst := copy (st1,1,i1)
else tempst := st1;
leftstr := tempst;
end;
(* Equivalent for the BASIC RIGHT$(A$,M) *)
(* Returns the right i1 characters of st1 *)
function rightstr (st1: line; i1: byte): line;
var
tempst : line;
n : byte;
begin
n := length (st1);
if (n <= i1) then tempst := st1
else tempst := copy (st1,n-i1+1,i1);
rightstr := tempst;
end; (* rightstr *)
(* Checks, if File 'filnam' exists on disk *)
function exist (filnam: line): boolean;
var
fil: file;
bool: boolean;
begin
assign (fil,filnam);
{$I-} reset (fil) {$I+};
bool := (ioresult=0);
if bool then close (fil);
exist := bool;
end; (* exist *)
(* Write a line of text to a byte_type file *)
procedure write_text_to_file (var fil: byte_type;
zeile: line;
var result: integer);
var
st1,character : byte;
begin
st1 := 1;
result := 0;
while ((st1 <= length (zeile)) and (result = 0)) do
begin
character := ord (copy (zeile,st1,1));
{$I-} write (fil,character); {$I+}
result := ioresult;
st1 := succ (st1)
end
end; (* schreib *)
(* Open a file for APPEND *)
(* To close this file, please use close_append to keep the file *)
(* WordStar-compatible. Close_append writes a ^Z at the EOF! *)
procedure opena (var fil: byte_type; filename: line; var error: integer);
var
position : real;
test : byte;
search : boolean;
begin
if exist (filename) then
begin
assign (fil, filename);
{$I-} reset (fil) {$I+};
error := ioresult;
if (error = 0) then
begin
LongSeek (fil,LongFileSize(fil));
for test := 1 to 5 do write (fil,eof_mark); { make sure eof is marked }
position := LongFilePos(fil) - 2.0;
repeat
position := position - 1.0;
LongSeek (fil,position);
read (fil,test);
until ((test <> eof_mark) or (position < 1.0));
if (position < 1.0) then LongSeek (fil,position)
end
end
else
begin
assign (fil, filename);
{$I-} rewrite (fil) {$I+};
error := ioresult
end
end; (* opena *)
(* close APPEND-File *)
procedure close_append (var fil: byte_type);
var
murks : integer;
begin
{$I-}
write (fil,eof_mark);
murks := ioresult;
close (fil);
murks := ioresult;
{$I+}
end; (* close_append *)
(* This procedure responds to ANY key ! *)
procedure wait_for_any_key;
var
status : byte;
begin
delay (1000);
status := (mem[$0000:$0417] and 176); { save state of NUM-CAPS-INS-Lock }
mem[$0000:$0417] := 32; { now force NUM-Lock for 5-Key ! }
repeat until (keypressed or (mem[$0000:$0417]<>32));
mem[$0000:$0417] := status; { restore old Locks }
mem[$0000:1050] := mem[$0000:1052]; { empty keyboard-buffer }
end; (* wait_for_any_key *)
(* This procedure displays the state of INS-CAPS-NUM-Locks and Shift-keys *)
(* in the lower right corner of the screen *)
(* Make sure to WINDOW-protect the last line ! *)
procedure lock_status;
function ins_lock : boolean;
begin
ins_lock := ((mem[0000:$417] and 128) <> 0);
end; (* ins_lock *)
function num_lock : boolean;
begin
num_lock := ((mem[0000:$417] and 32) <> 0);
end; (* num_lock *)
function caps_lock : boolean;
begin
caps_lock := ((mem[0000:$417] and 64) <> 0);
end; (* caps_lock *)
function shift : boolean;
begin
shift := ((mem[0000:$417] and 3) <> 0);
end; (* shift *)
begin
if num_lock then mem[ScreenBase:Offset + 312] := ord('N')
else mem[ScreenBase:Offset + 312] := 32;
if ins_lock then mem[ScreenBase:Offset + 314] := ord('I')
else mem[ScreenBase:Offset + 314] := 32;
if caps_lock then mem[ScreenBase:Offset + 316] := ord('C')
else mem[ScreenBase:Offset + 316] := 32;
if shift then mem[ScreenBase:Offset + 318] := ord('S')
else mem[ScreenBase:Offset + 318] := 32;
end; (* lock_status *)
begin (* DEMO *)
DetermineDisplay;
write ('You have a ');
if (ScreenBase = $B800) then write ('Colour')
else write ('Monochrome');
writeln ('-Display installed.');
writeln;
demochar := 'A';
writeln ('Try the locks, hit <SPACE> to continue ...');
repeat
lock_status;
if keypressed then read (kbd, demochar);
until (demochar = ' ');
ClrScr;
writeln ('Now hit any key to exit ...');
wait_for_any_key;
sound (1000);
delay (1000);
nosound;
end. (* of DEMO *)